package board

import (
	"../io"
	"math/rand"
	"time"
)

type Rule interface {
	NumPlayers() int
	Deal(cards io.CardSlice, numPlayers int, remainNumCards int) (outCards []io.CardSlice, remainCards io.CardSlice)
}

type DefaultRule struct {

}

func (p* DefaultRule) Deal(cards io.CardSlice, numPlayers int, remainNumCards int) (outCards []io.CardSlice, remainCards io.CardSlice) {
	allCards := cards[:]
	outCards = make([]io.CardSlice, numPlayers)
	for i := 0; i < numPlayers; i++ {
		outCards[i] = []io.Card{}
	}

	chair := 0
	rand.Seed(int64(time.Now().Nanosecond()))
	for len(allCards) > remainNumCards {
		l := rand.Intn(len(allCards))
		card := allCards[l]
		allCards = append(allCards[0:l], allCards[l + 1:]...)
		outCards[chair] = append(outCards[chair], card)

		chair = (chair + 1) % numPlayers
	}

	remainCards = allCards

	return
}